<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>perlxstypemap - Perl XS C/Perl type mapping - Perldoc Browser</title>
    <link rel="search" href="https://perldoc.perl.org/opensearch.xml" type="application/opensearchdescription+xml" title="Perldoc Browser">
    <link rel="canonical" href="https://perldoc.perl.org/perlxstypemap">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/stackoverflow-light.min.css" integrity="sha512-cG1IdFxqipi3gqLmksLtuk13C+hBa57a6zpWxMeoY3Q9O6ooFxq50DayCdm0QrDgZjMUn23z/0PMZlgft7Yp5Q==" crossorigin="anonymous" />
    <style>
      body {
        background: #f4f4f5;
        color: #020202;
      }
      .navbar-dark {
        background-image: -webkit-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: -o-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: linear-gradient(to bottom, #005f85 0, #002e49 100%);
        filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff005f85', endColorstr='#ff002e49', GradientType=0);
        background-repeat: repeat-x;
      }
      .navbar-dark .navbar-nav .nav-link,
      .navbar-dark .navbar-nav .nav-link:focus { color: #fff }
      .navbar-dark .navbar-nav .nav-link:hover { color: #ffef68 }
      #wrapperlicious {
        margin: 0 auto;
        font: 0.9em 'Helvetica Neue', Helvetica, sans-serif;
        font-weight: normal;
        line-height: 1.5em;
        margin: 0;
        padding: 0;
      }
      #wrapperlicious h1 { font-size: 1.5em }
      #wrapperlicious h2 { font-size: 1.3em }
      #wrapperlicious h3 { font-size: 1.1em }
      #wrapperlicious h4 { font-size: 0.9em }
      #wrapperlicious h1, #wrapperlicious h2, #wrapperlicious h3,
      #wrapperlicious h4, #wrapperlicious dt {
        color: #020202;
        margin-top: 1em;
        margin-bottom: 1em;
        position: relative;
        font-weight: bold;
      }
      #wrapperlicious a { color: inherit; text-decoration: underline }
      #wrapperlicious #toc { text-decoration: none }
      #wrapperlicious a:hover { color: #2a2a2a }
      #wrapperlicious a img { border: 0 }
      #wrapperlicious :not(pre) > code {
        color: inherit;
        background-color: rgba(0, 0, 0, 0.04);
        border-radius: 3px;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        padding: 0.3em;
      }
      #wrapperlicious dd {
        margin: 0;
        margin-left: 2em;
      }
      #wrapperlicious dt {
        color: #2a2a2a;
        font-weight: bold;
        margin-left: 0.9em;
      }
      #wrapperlicious p {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious li > p {
        margin-bottom: 0;
        margin-top: 0;
      }
      #wrapperlicious pre {
        border: 1px solid #c1c1c1;
        border-radius: 3px;
        font: 100% Consolas, Menlo, Monaco, monospace;
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious pre > code {
        display: block;
        background-color: #f6f6f6;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        line-height: 1.5em;
        text-align: left;
        white-space: pre;
        padding: 1em;
      }
      #wrapperlicious dl, #wrapperlicious ol, #wrapperlicious ul {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious ul {
        list-style-type: square;
      }
      #wrapperlicious ul ul {
        margin-bottom: 0px;
        margin-top: 0px;
      }
      #footer {
        font-size: 0.8em;
        padding-top: 0.5em;
        text-align: center;
      }
      #more {
        display: inline;
        font-size: 0.8em;
      }
      #perldocdiv {
        background-color: #fff;
        border: 1px solid #c1c1c1;
        border-bottom-left-radius: 5px;
        border-bottom-right-radius: 5px;
        margin-left: auto;
        margin-right: auto;
        padding: 3em;
        padding-top: 1em;
        max-width: 960px;
      }
      #moduleversion { float: right }
      #wrapperlicious .leading-notice {
        font-style: italic;
        padding-left: 1em;
        margin-top: 1em;
        margin-bottom: 1em;
      }
      #wrapperlicious .permalink {
        display: none;
        left: -0.75em;
        position: absolute;
        padding-right: 0.25em;
        text-decoration: none;
      }
      #wrapperlicious h1:hover .permalink, #wrapperlicious h2:hover .permalink,
      #wrapperlicious h3:hover .permalink, #wrapperlicious h4:hover .permalink,
      #wrapperlicious dt:hover .permalink {
        display: block;
      }
    </style>
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-KVNWBNT5FB"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());

      gtag('config', 'G-KVNWBNT5FB');
      gtag('config', 'UA-50555-3');
    </script>
  </head>
  <body>
    <nav class="navbar navbar-expand-md navbar-dark bg-dark justify-content-between">
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <a class="navbar-brand" href="https://perldoc.perl.org/">Perldoc Browser</a>
  <div class="collapse navbar-collapse" id="navbarNav">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="perlxstypemap.html#" id="dropdownlink-stable" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">5.35.0</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-stable">
          <a class="dropdown-item" href="https://perldoc.perl.org/perlxstypemap">Latest</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.2/perlxstypemap">5.38.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.1/perlxstypemap">5.38.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0/perlxstypemap">5.38.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.3/perlxstypemap">5.36.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.2/perlxstypemap">5.36.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.1/perlxstypemap">5.36.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.0/perlxstypemap">5.36.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.3/perlxstypemap">5.34.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.2/perlxstypemap">5.34.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.1/perlxstypemap">5.34.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.0/perlxstypemap">5.34.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.1/perlxstypemap">5.32.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.0/perlxstypemap">5.32.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.3/perlxstypemap">5.30.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.2/perlxstypemap">5.30.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.1/perlxstypemap">5.30.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.0/perlxstypemap">5.30.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.3/perlxstypemap">5.28.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.2/perlxstypemap">5.28.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.1/perlxstypemap">5.28.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.0/perlxstypemap">5.28.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.3/perlxstypemap">5.26.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.2/perlxstypemap">5.26.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.1/perlxstypemap">5.26.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.0/perlxstypemap">5.26.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.4/perlxstypemap">5.24.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.3/perlxstypemap">5.24.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.2/perlxstypemap">5.24.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.1/perlxstypemap">5.24.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.0/perlxstypemap">5.24.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.4/perlxstypemap">5.22.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.3/perlxstypemap">5.22.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.2/perlxstypemap">5.22.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.1/perlxstypemap">5.22.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.0/perlxstypemap">5.22.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.3/perlxstypemap">5.20.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.2/perlxstypemap">5.20.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.1/perlxstypemap">5.20.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.0/perlxstypemap">5.20.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.4/perlxstypemap">5.18.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.3/perlxstypemap">5.18.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.2/perlxstypemap">5.18.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.1/perlxstypemap">5.18.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.0/perlxstypemap">5.18.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.3/perlxstypemap">5.16.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.2/perlxstypemap">5.16.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.1/perlxstypemap">5.16.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.0/perlxstypemap">5.16.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.4/perlxstypemap">5.14.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.3/perlxstypemap">5.14.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.2/perlxstypemap">5.14.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.1/perlxstypemap">5.14.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.0/perlxstypemap">5.14.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.5/perlxstypemap">5.12.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.4/perlxstypemap">5.12.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.3/perlxstypemap">5.12.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.2/perlxstypemap">5.12.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.1/perlxstypemap">5.12.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.0/perlxstypemap">5.12.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.1/perlxstypemap">5.10.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.0/perlxstypemap">5.10.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.9/perlxstypemap">5.8.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.8/perlxstypemap">5.8.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.7/perlxstypemap">5.8.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.6/perlxstypemap">5.8.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.5/perlxstypemap">5.8.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.4/perlxstypemap">5.8.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.3/perlxstypemap">5.8.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.2/perlxstypemap">5.8.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.1/perlxstypemap">5.8.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.0/perlxstypemap">5.8.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.2/perlxstypemap">5.6.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.1/perlxstypemap">5.6.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.0/perlxstypemap">5.6.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_04/perlxstypemap">5.005_04</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_03/perlxstypemap">5.005_03</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_02/perlxstypemap">5.005_02</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_01/perlxstypemap">5.005_01</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005/perlxstypemap">5.005</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="perlxstypemap.html#" id="dropdownlink-dev" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dev</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-dev">
          <a class="dropdown-item" href="https://perldoc.perl.org/blead/perlxstypemap">blead</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.6/perlxstypemap">5.39.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.5/perlxstypemap">5.39.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.4/perlxstypemap">5.39.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.3/perlxstypemap">5.39.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.2/perlxstypemap">5.39.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.1/perlxstypemap">5.39.1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC2/perlxstypemap">5.38.0-RC2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC1/perlxstypemap">5.38.0-RC1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.11/perlxstypemap">5.37.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.10/perlxstypemap">5.37.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.9/perlxstypemap">5.37.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.8/perlxstypemap">5.37.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.7/perlxstypemap">5.37.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.6/perlxstypemap">5.37.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.5/perlxstypemap">5.37.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.4/perlxstypemap">5.37.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.3/perlxstypemap">5.37.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.2/perlxstypemap">5.37.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.1/perlxstypemap">5.37.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.0/perlxstypemap">5.37.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.11/perlxstypemap">5.35.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.10/perlxstypemap">5.35.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.9/perlxstypemap">5.35.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.8/perlxstypemap">5.35.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.7/perlxstypemap">5.35.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.6/perlxstypemap">5.35.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.5/perlxstypemap">5.35.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.4/perlxstypemap">5.35.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.3/perlxstypemap">5.35.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.2/perlxstypemap">5.35.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.1/perlxstypemap">5.35.1</a>
          <a class="dropdown-item active" href="perlxstypemap.html">5.35.0</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="perlxstypemap.html#" id="dropdownlink-nav" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Documentation</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-nav">
          <a class="dropdown-item" href="perl.html">Perl</a>
          <a class="dropdown-item" href="perlintro.html">Intro</a>
          <a class="dropdown-item" href="perl.html#Tutorials">Tutorials</a>
          <a class="dropdown-item" href="perlfaq.html">FAQs</a>
          <a class="dropdown-item" href="perl.html#Reference-Manual">Reference</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlop.html">Operators</a>
          <a class="dropdown-item" href="functions.html">Functions</a>
          <a class="dropdown-item" href="variables.html">Variables</a>
          <a class="dropdown-item" href="modules.html">Modules</a>
          <a class="dropdown-item" href="perlutil.html">Utilities</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlcommunity.html">Community</a>
          <a class="dropdown-item" href="perlhist.html">History</a>
        </div>
      </li>
    </ul>
    <ul class="navbar-nav">
      <script>
        function set_expand (expand) {
          var perldocdiv = document.getElementById('perldocdiv');
          var width = window.getComputedStyle(perldocdiv).getPropertyValue('max-width');
          var expanded = (width == '' || width == 'none') ? true : false;
          if (expand === null) {
            expand = !expanded;
          }
          if ((expand && !expanded) || (!expand && expanded)) {
            perldocdiv.style.setProperty('max-width', expand ? 'none' : '960px');
            var button_classlist = document.getElementById('content-expand-button').classList;
            if (expand) {
              button_classlist.add('btn-light');
              button_classlist.remove('btn-outline-light');
            } else {
              button_classlist.add('btn-outline-light');
              button_classlist.remove('btn-light');
            }
          }
          return expand;
        }
        function toggle_expand () {
          var expand = set_expand(null);
          document.cookie = 'perldoc_expand=' + (expand ? 1 : 0) + '; path=/; expires=Tue, 19 Jan 2038 03:14:07 UTC';
        }
        function read_expand () {
          return document.cookie.split(';').some(function (item) { return item.indexOf('perldoc_expand=1') >= 0 });
        }
        if (document.readyState === 'loading') {
          document.addEventListener('DOMContentLoaded', function () {
            if (read_expand()) {
              set_expand(true);
            }
          });
        } else if (read_expand()) {
          set_expand(true);
        }
      </script>
      <button id="content-expand-button" type="button" class="btn btn-outline-light d-none d-lg-inline-block mr-2" onclick="toggle_expand()">Expand</button>
    <ul>
    <form class="form-inline" method="get" action="https://perldoc.perl.org/5.35.0/search">
      <input class="form-control mr-3" type="search" name="q" placeholder="Search" aria-label="Search">
    </form>
  </div>
</nav>

    <div id="wrapperlicious" class="container-fluid">
      <div id="perldocdiv">
        <div id="links">
          <a href="perlxstypemap.html">perlxstypemap</a>
          <div id="more">
            (<a href="perlxstypemap.txt">source</a>,
            <a href="https://metacpan.org/pod/perlxstypemap">CPAN</a>)
          </div>
        </div>
        <div class="leading-notice">
          You are viewing the version of this documentation from Perl 5.35.0.
            This is a development version of Perl.
        </div>
        <h1><a id="toc">CONTENTS</a></h1>
                  <ul>
              <li>
                <a class="text-decoration-none" href="perlxstypemap.html#NAME">NAME</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlxstypemap.html#DESCRIPTION">DESCRIPTION</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="perlxstypemap.html#Anatomy-of-a-typemap">Anatomy of a typemap</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlxstypemap.html#The-Role-of-the-typemap-File-in-Your-Distribution">The Role of the typemap File in Your Distribution</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlxstypemap.html#Sharing-typemaps-Between-CPAN-Distributions">Sharing typemaps Between CPAN Distributions</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlxstypemap.html#Writing-typemap-Entries">Writing typemap Entries</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlxstypemap.html#Full-Listing-of-Core-Typemaps">Full Listing of Core Typemaps</a>
              </li>
          </ul>

              </li>
          </ul>

      <h1 id="NAME"><a class="permalink" href="perlxstypemap.html#NAME">#</a>NAME</h1>

<p>perlxstypemap - Perl XS C/Perl type mapping</p>

<h1 id="DESCRIPTION"><a class="permalink" href="perlxstypemap.html#DESCRIPTION">#</a>DESCRIPTION</h1>

<p>The more you think about interfacing between two languages, the more you&#39;ll realize that the majority of programmer effort has to go into converting between the data structures that are native to either of the languages involved. This trumps other matter such as differing calling conventions because the problem space is so much greater. There are simply more ways to shove data into memory than there are ways to implement a function call.</p>

<p>Perl XS&#39; attempt at a solution to this is the concept of typemaps. At an abstract level, a Perl XS typemap is nothing but a recipe for converting from a certain Perl data structure to a certain C data structure and vice versa. Since there can be C types that are sufficiently similar to one another to warrant converting with the same logic, XS typemaps are represented by a unique identifier, henceforth called an <b>XS type</b> in this document. You can then tell the XS compiler that multiple C types are to be mapped with the same XS typemap.</p>

<p>In your XS code, when you define an argument with a C type or when you are using a <code>CODE:</code> and an <code>OUTPUT:</code> section together with a C return type of your XSUB, it&#39;ll be the typemapping mechanism that makes this easy.</p>

<h2 id="Anatomy-of-a-typemap"><a class="permalink" href="perlxstypemap.html#Anatomy-of-a-typemap">#</a><a id="Anatomy"></a>Anatomy of a typemap</h2>

<p>In more practical terms, the typemap is a collection of code fragments which are used by the <b>xsubpp</b> compiler to map C function parameters and values to Perl values. The typemap file may consist of three sections labelled <code>TYPEMAP</code>, <code>INPUT</code>, and <code>OUTPUT</code>. An unlabelled initial section is assumed to be a <code>TYPEMAP</code> section. The INPUT section tells the compiler how to translate Perl values into variables of certain C types. The OUTPUT section tells the compiler how to translate the values from certain C types into values Perl can understand. The TYPEMAP section tells the compiler which of the INPUT and OUTPUT code fragments should be used to map a given C type to a Perl value. The section labels <code>TYPEMAP</code>, <code>INPUT</code>, or <code>OUTPUT</code> must begin in the first column on a line by themselves, and must be in uppercase.</p>

<p>Each type of section can appear an arbitrary number of times and does not have to appear at all. For example, a typemap may commonly lack <code>INPUT</code> and <code>OUTPUT</code> sections if all it needs to do is associate additional C types with core XS types like T_PTROBJ. Lines that start with a hash <code>#</code> are considered comments and ignored in the <code>TYPEMAP</code> section, but are considered significant in <code>INPUT</code> and <code>OUTPUT</code>. Blank lines are generally ignored.</p>

<p>Traditionally, typemaps needed to be written to a separate file, conventionally called <code>typemap</code> in a CPAN distribution. With ExtUtils::ParseXS (the XS compiler) version 3.12 or better which comes with perl 5.16, typemaps can also be embedded directly into XS code using a HERE-doc like syntax:</p>

<pre><code class="plaintext">TYPEMAP: &lt;&lt;HERE
...
HERE</code></pre>

<p>where <code>HERE</code> can be replaced by other identifiers like with normal Perl HERE-docs. All details below about the typemap textual format remain valid.</p>

<p>The <code>TYPEMAP</code> section should contain one pair of C type and XS type per line as follows. An example from the core typemap file:</p>

<pre><code class="plaintext">TYPEMAP
# all variants of char* is handled by the T_PV typemap
char *          T_PV
const char *    T_PV
unsigned char * T_PV
...</code></pre>

<p>The <code>INPUT</code> and <code>OUTPUT</code> sections have identical formats, that is, each unindented line starts a new in- or output map respectively. A new in- or output map must start with the name of the XS type to map on a line by itself, followed by the code that implements it indented on the following lines. Example:</p>

<pre><code>INPUT
T_PV
  $var = ($type)SvPV_nolen($arg)
T_PTR
  $var = INT2PTR($type,SvIV($arg))</code></pre>

<p>We&#39;ll get to the meaning of those Perlish-looking variables in a little bit.</p>

<p>Finally, here&#39;s an example of the full typemap file for mapping C strings of the <code>char *</code> type to Perl scalars/strings:</p>

<pre><code>TYPEMAP
char *  T_PV

INPUT
T_PV
  $var = ($type)SvPV_nolen($arg)

OUTPUT
T_PV
  sv_setpv((SV*)$arg, $var);</code></pre>

<p>Here&#39;s a more complicated example: suppose that you wanted <code>struct netconfig</code> to be blessed into the class <code>Net::Config</code>. One way to do this is to use underscores (_) to separate package names, as follows:</p>

<pre><code>typedef struct netconfig * Net_Config;</code></pre>

<p>And then provide a typemap entry <code>T_PTROBJ_SPECIAL</code> that maps underscores to double-colons (::), and declare <code>Net_Config</code> to be of that type:</p>

<pre><code>TYPEMAP
Net_Config      T_PTROBJ_SPECIAL

INPUT
T_PTROBJ_SPECIAL
  if (sv_derived_from($arg, \&quot;${(my $ntt=$ntype)=~s/_/::/g;\$ntt}\&quot;)){
    IV tmp = SvIV((SV*)SvRV($arg));
    $var = INT2PTR($type, tmp);
  }
  else
    croak(\&quot;$var is not of type ${(my $ntt=$ntype)=~s/_/::/g;\$ntt}\&quot;)

OUTPUT
T_PTROBJ_SPECIAL
  sv_setref_pv($arg, \&quot;${(my $ntt=$ntype)=~s/_/::/g;\$ntt}\&quot;,
               (void*)$var);</code></pre>

<p>The INPUT and OUTPUT sections substitute underscores for double-colons on the fly, giving the desired effect. This example demonstrates some of the power and versatility of the typemap facility.</p>

<p>The <code>INT2PTR</code> macro (defined in perl.h) casts an integer to a pointer of a given type, taking care of the possible different size of integers and pointers. There are also <code>PTR2IV</code>, <code>PTR2UV</code>, <code>PTR2NV</code> macros, to map the other way, which may be useful in OUTPUT sections.</p>

<h2 id="The-Role-of-the-typemap-File-in-Your-Distribution"><a class="permalink" href="perlxstypemap.html#The-Role-of-the-typemap-File-in-Your-Distribution">#</a><a id="The"></a>The Role of the typemap File in Your Distribution</h2>

<p>The default typemap in the <i>lib/ExtUtils</i> directory of the Perl source contains many useful types which can be used by Perl extensions. Some extensions define additional typemaps which they keep in their own directory. These additional typemaps may reference INPUT and OUTPUT maps in the main typemap. The <b>xsubpp</b> compiler will allow the extension&#39;s own typemap to override any mappings which are in the default typemap. Instead of using an additional <i>typemap</i> file, typemaps may be embedded verbatim in XS with a heredoc-like syntax. See the documentation on the <code>TYPEMAP:</code> XS keyword.</p>

<p>For CPAN distributions, you can assume that the XS types defined by the perl core are already available. Additionally, the core typemap has default XS types for a large number of C types. For example, if you simply return a <code>char *</code> from your XSUB, the core typemap will have this C type associated with the T_PV XS type. That means your C string will be copied into the PV (pointer value) slot of a new scalar that will be returned from your XSUB to Perl.</p>

<p>If you&#39;re developing a CPAN distribution using XS, you may add your own file called <i>typemap</i> to the distribution. That file may contain typemaps that either map types that are specific to your code or that override the core typemap file&#39;s mappings for common C types.</p>

<h2 id="Sharing-typemaps-Between-CPAN-Distributions"><a class="permalink" href="perlxstypemap.html#Sharing-typemaps-Between-CPAN-Distributions">#</a><a id="Sharing"></a>Sharing typemaps Between CPAN Distributions</h2>

<p>Starting with ExtUtils::ParseXS version 3.13_01 (comes with perl 5.16 and better), it is rather easy to share typemap code between multiple CPAN distributions. The general idea is to share it as a module that offers a certain API and have the dependent modules declare that as a built-time requirement and import the typemap into the XS. An example of such a typemap-sharing module on CPAN is <code>ExtUtils::Typemaps::Basic</code>. Two steps to getting that module&#39;s typemaps available in your code:</p>

<ul>

<li><p>Declare <code>ExtUtils::Typemaps::Basic</code> as a build-time dependency in <code>Makefile.PL</code> (use <code>BUILD_REQUIRES</code>), or in your <code>Build.PL</code> (use <code>build_requires</code>).</p>

</li>
<li><p>Include the following line in the XS section of your XS file: (don&#39;t break the line)</p>

<pre><code class="plaintext">INCLUDE_COMMAND: $^X -MExtUtils::Typemaps::Cmd
                 -e &quot;print embeddable_typemap(q{Basic})&quot;</code></pre>

</li>
</ul>

<h2 id="Writing-typemap-Entries"><a class="permalink" href="perlxstypemap.html#Writing-typemap-Entries">#</a><a id="Writing"></a>Writing typemap Entries</h2>

<p>Each INPUT or OUTPUT typemap entry is a double-quoted Perl string that will be evaluated in the presence of certain variables to get the final C code for mapping a certain C type.</p>

<p>This means that you can embed Perl code in your typemap (C) code using constructs such as <code>${ perl code that evaluates to scalar reference here }</code>. A common use case is to generate error messages that refer to the true function name even when using the ALIAS XS feature:</p>

<pre><code>${ $ALIAS ? \q[GvNAME(CvGV(cv))] : \qq[\&quot;$pname\&quot;] }</code></pre>

<p>For many typemap examples, refer to the core typemap file that can be found in the perl source tree at <i>lib/ExtUtils/typemap</i>.</p>

<p>The Perl variables that are available for interpolation into typemaps are the following:</p>

<ul>

<li><p><i>$var</i> - the name of the input or output variable, eg. RETVAL for return values.</p>

</li>
<li><p><i>$type</i> - the raw C type of the parameter, any <code>:</code> replaced with <code>_</code>. e.g. for a type of <code>Foo::Bar</code>, <i>$type</i> is <code>Foo__Bar</code></p>

</li>
<li><p><i>$ntype</i> - the supplied type with <code>*</code> replaced with <code>Ptr</code>. e.g. for a type of <code>Foo*</code>, <i>$ntype</i> is <code>FooPtr</code></p>

</li>
<li><p><i>$arg</i> - the stack entry, that the parameter is input from or output to, e.g. <code>ST(0)</code></p>

</li>
<li><p><i>$argoff</i> - the argument stack offset of the argument. ie. 0 for the first argument, etc.</p>

</li>
<li><p><i>$pname</i> - the full name of the XSUB, with including the <code>PACKAGE</code> name, with any <code>PREFIX</code> stripped. This is the non-ALIAS name.</p>

</li>
<li><p><i>$Package</i> - the package specified by the most recent <code>PACKAGE</code> keyword.</p>

</li>
<li><p><i>$ALIAS</i> - non-zero if the current XSUB has any aliases declared with <code>ALIAS</code>.</p>

</li>
</ul>

<h2 id="Full-Listing-of-Core-Typemaps"><a class="permalink" href="perlxstypemap.html#Full-Listing-of-Core-Typemaps">#</a><a id="Full"></a>Full Listing of Core Typemaps</h2>

<p>Each C type is represented by an entry in the typemap file that is responsible for converting perl variables (SV, AV, HV, CV, etc.) to and from that type. The following sections list all XS types that come with perl by default.</p>

<dl>

<dt id="T_SV"><a class="permalink" href="perlxstypemap.html#T_SV">#</a>T_SV</dt>
<dd>

<p>This simply passes the C representation of the Perl variable (an SV*) in and out of the XS layer. This can be used if the C code wants to deal directly with the Perl variable.</p>

</dd>
<dt id="T_SVREF"><a class="permalink" href="perlxstypemap.html#T_SVREF">#</a>T_SVREF</dt>
<dd>

<p>Used to pass in and return a reference to an SV.</p>

<p>Note that this typemap does not decrement the reference count when returning the reference to an SV*. See also: T_SVREF_REFCOUNT_FIXED</p>

</dd>
<dt id="T_SVREF_FIXED"><a class="permalink" href="perlxstypemap.html#T_SVREF_FIXED">#</a>T_SVREF_FIXED</dt>
<dd>

<p>Used to pass in and return a reference to an SV. This is a fixed variant of T_SVREF that decrements the refcount appropriately when returning a reference to an SV*. Introduced in perl 5.15.4.</p>

</dd>
<dt id="T_AVREF"><a class="permalink" href="perlxstypemap.html#T_AVREF">#</a>T_AVREF</dt>
<dd>

<p>From the perl level this is a reference to a perl array. From the C level this is a pointer to an AV.</p>

<p>Note that this typemap does not decrement the reference count when returning an AV*. See also: T_AVREF_REFCOUNT_FIXED</p>

</dd>
<dt id="T_AVREF_REFCOUNT_FIXED"><a class="permalink" href="perlxstypemap.html#T_AVREF_REFCOUNT_FIXED">#</a>T_AVREF_REFCOUNT_FIXED</dt>
<dd>

<p>From the perl level this is a reference to a perl array. From the C level this is a pointer to an AV. This is a fixed variant of T_AVREF that decrements the refcount appropriately when returning an AV*. Introduced in perl 5.15.4.</p>

</dd>
<dt id="T_HVREF"><a class="permalink" href="perlxstypemap.html#T_HVREF">#</a>T_HVREF</dt>
<dd>

<p>From the perl level this is a reference to a perl hash. From the C level this is a pointer to an HV.</p>

<p>Note that this typemap does not decrement the reference count when returning an HV*. See also: T_HVREF_REFCOUNT_FIXED</p>

</dd>
<dt id="T_HVREF_REFCOUNT_FIXED"><a class="permalink" href="perlxstypemap.html#T_HVREF_REFCOUNT_FIXED">#</a>T_HVREF_REFCOUNT_FIXED</dt>
<dd>

<p>From the perl level this is a reference to a perl hash. From the C level this is a pointer to an HV. This is a fixed variant of T_HVREF that decrements the refcount appropriately when returning an HV*. Introduced in perl 5.15.4.</p>

</dd>
<dt id="T_CVREF"><a class="permalink" href="perlxstypemap.html#T_CVREF">#</a>T_CVREF</dt>
<dd>

<p>From the perl level this is a reference to a perl subroutine (e.g. $sub = sub { 1 };). From the C level this is a pointer to a CV.</p>

<p>Note that this typemap does not decrement the reference count when returning an HV*. See also: T_HVREF_REFCOUNT_FIXED</p>

</dd>
<dt id="T_CVREF_REFCOUNT_FIXED"><a class="permalink" href="perlxstypemap.html#T_CVREF_REFCOUNT_FIXED">#</a>T_CVREF_REFCOUNT_FIXED</dt>
<dd>

<p>From the perl level this is a reference to a perl subroutine (e.g. $sub = sub { 1 };). From the C level this is a pointer to a CV.</p>

<p>This is a fixed variant of T_HVREF that decrements the refcount appropriately when returning an HV*. Introduced in perl 5.15.4.</p>

</dd>
<dt id="T_SYSRET"><a class="permalink" href="perlxstypemap.html#T_SYSRET">#</a>T_SYSRET</dt>
<dd>

<p>The T_SYSRET typemap is used to process return values from system calls. It is only meaningful when passing values from C to perl (there is no concept of passing a system return value from Perl to C).</p>

<p>System calls return -1 on error (setting ERRNO with the reason) and (usually) 0 on success. If the return value is -1 this typemap returns <code>undef</code>. If the return value is not -1, this typemap translates a 0 (perl false) to &quot;0 but true&quot; (which is perl true) or returns the value itself, to indicate that the command succeeded.</p>

<p>The <a href="POSIX.html">POSIX</a> module makes extensive use of this type.</p>

</dd>
<dt id="T_UV"><a class="permalink" href="perlxstypemap.html#T_UV">#</a>T_UV</dt>
<dd>

<p>An unsigned integer.</p>

</dd>
<dt id="T_IV"><a class="permalink" href="perlxstypemap.html#T_IV">#</a>T_IV</dt>
<dd>

<p>A signed integer. This is cast to the required integer type when passed to C and converted to an IV when passed back to Perl.</p>

</dd>
<dt id="T_INT"><a class="permalink" href="perlxstypemap.html#T_INT">#</a>T_INT</dt>
<dd>

<p>A signed integer. This typemap converts the Perl value to a native integer type (the <code>int</code> type on the current platform). When returning the value to perl it is processed in the same way as for T_IV.</p>

<p>Its behaviour is identical to using an <code>int</code> type in XS with T_IV.</p>

</dd>
<dt id="T_ENUM"><a class="permalink" href="perlxstypemap.html#T_ENUM">#</a>T_ENUM</dt>
<dd>

<p>An enum value. Used to transfer an enum component from C. There is no reason to pass an enum value to C since it is stored as an IV inside perl.</p>

</dd>
<dt id="T_BOOL"><a class="permalink" href="perlxstypemap.html#T_BOOL">#</a>T_BOOL</dt>
<dd>

<p>A boolean type. This can be used to pass true and false values to and from C.</p>

</dd>
<dt id="T_U_INT"><a class="permalink" href="perlxstypemap.html#T_U_INT">#</a>T_U_INT</dt>
<dd>

<p>This is for unsigned integers. It is equivalent to using T_UV but explicitly casts the variable to type <code>unsigned int</code>. The default type for <code>unsigned int</code> is T_UV.</p>

</dd>
<dt id="T_SHORT"><a class="permalink" href="perlxstypemap.html#T_SHORT">#</a>T_SHORT</dt>
<dd>

<p>Short integers. This is equivalent to T_IV but explicitly casts the return to type <code>short</code>. The default typemap for <code>short</code> is T_IV.</p>

</dd>
<dt id="T_U_SHORT"><a class="permalink" href="perlxstypemap.html#T_U_SHORT">#</a>T_U_SHORT</dt>
<dd>

<p>Unsigned short integers. This is equivalent to T_UV but explicitly casts the return to type <code>unsigned short</code>. The default typemap for <code>unsigned short</code> is T_UV.</p>

<p>T_U_SHORT is used for type <code>U16</code> in the standard typemap.</p>

</dd>
<dt id="T_LONG"><a class="permalink" href="perlxstypemap.html#T_LONG">#</a>T_LONG</dt>
<dd>

<p>Long integers. This is equivalent to T_IV but explicitly casts the return to type <code>long</code>. The default typemap for <code>long</code> is T_IV.</p>

</dd>
<dt id="T_U_LONG"><a class="permalink" href="perlxstypemap.html#T_U_LONG">#</a>T_U_LONG</dt>
<dd>

<p>Unsigned long integers. This is equivalent to T_UV but explicitly casts the return to type <code>unsigned long</code>. The default typemap for <code>unsigned long</code> is T_UV.</p>

<p>T_U_LONG is used for type <code>U32</code> in the standard typemap.</p>

</dd>
<dt id="T_CHAR"><a class="permalink" href="perlxstypemap.html#T_CHAR">#</a>T_CHAR</dt>
<dd>

<p>Single 8-bit characters.</p>

</dd>
<dt id="T_U_CHAR"><a class="permalink" href="perlxstypemap.html#T_U_CHAR">#</a>T_U_CHAR</dt>
<dd>

<p>An unsigned byte.</p>

</dd>
<dt id="T_FLOAT"><a class="permalink" href="perlxstypemap.html#T_FLOAT">#</a>T_FLOAT</dt>
<dd>

<p>A floating point number. This typemap guarantees to return a variable cast to a <code>float</code>.</p>

</dd>
<dt id="T_NV"><a class="permalink" href="perlxstypemap.html#T_NV">#</a>T_NV</dt>
<dd>

<p>A Perl floating point number. Similar to T_IV and T_UV in that the return type is cast to the requested numeric type rather than to a specific type.</p>

</dd>
<dt id="T_DOUBLE"><a class="permalink" href="perlxstypemap.html#T_DOUBLE">#</a>T_DOUBLE</dt>
<dd>

<p>A double precision floating point number. This typemap guarantees to return a variable cast to a <code>double</code>.</p>

</dd>
<dt id="T_PV"><a class="permalink" href="perlxstypemap.html#T_PV">#</a>T_PV</dt>
<dd>

<p>A string (char *).</p>

</dd>
<dt id="T_PTR"><a class="permalink" href="perlxstypemap.html#T_PTR">#</a>T_PTR</dt>
<dd>

<p>A memory address (pointer). Typically associated with a <code>void *</code> type.</p>

</dd>
<dt id="T_PTRREF"><a class="permalink" href="perlxstypemap.html#T_PTRREF">#</a>T_PTRREF</dt>
<dd>

<p>Similar to T_PTR except that the pointer is stored in a scalar and the reference to that scalar is returned to the caller. This can be used to hide the actual pointer value from the programmer since it is usually not required directly from within perl.</p>

<p>The typemap checks that a scalar reference is passed from perl to XS.</p>

</dd>
<dt id="T_PTROBJ"><a class="permalink" href="perlxstypemap.html#T_PTROBJ">#</a>T_PTROBJ</dt>
<dd>

<p>Similar to T_PTRREF except that the reference is blessed into a class. This allows the pointer to be used as an object. Most commonly used to deal with C structs. The typemap checks that the perl object passed into the XS routine is of the correct class (or part of a subclass).</p>

<p>The pointer is blessed into a class that is derived from the name of type of the pointer but with all &#39;*&#39; in the name replaced with &#39;Ptr&#39;.</p>

<p>For <code>DESTROY</code> XSUBs only, a T_PTROBJ is optimized to a T_PTRREF. This means the class check is skipped.</p>

</dd>
<dt id="T_REF_IV_REF"><a class="permalink" href="perlxstypemap.html#T_REF_IV_REF">#</a>T_REF_IV_REF</dt>
<dd>

<p>NOT YET</p>

</dd>
<dt id="T_REF_IV_PTR"><a class="permalink" href="perlxstypemap.html#T_REF_IV_PTR">#</a>T_REF_IV_PTR</dt>
<dd>

<p>Similar to T_PTROBJ in that the pointer is blessed into a scalar object. The difference is that when the object is passed back into XS it must be of the correct type (inheritance is not supported) while T_PTROBJ supports inheritance.</p>

<p>The pointer is blessed into a class that is derived from the name of type of the pointer but with all &#39;*&#39; in the name replaced with &#39;Ptr&#39;.</p>

<p>For <code>DESTROY</code> XSUBs only, a T_REF_IV_PTR is optimized to a T_PTRREF. This means the class check is skipped.</p>

</dd>
<dt id="T_PTRDESC"><a class="permalink" href="perlxstypemap.html#T_PTRDESC">#</a>T_PTRDESC</dt>
<dd>

<p>NOT YET</p>

</dd>
<dt id="T_REFREF"><a class="permalink" href="perlxstypemap.html#T_REFREF">#</a>T_REFREF</dt>
<dd>

<p>Similar to T_PTRREF, except the pointer stored in the referenced scalar is dereferenced and copied to the output variable. This means that T_REFREF is to T_PTRREF as T_OPAQUE is to T_OPAQUEPTR. All clear?</p>

<p>Only the INPUT part of this is implemented (Perl to XSUB) and there are no known users in core or on CPAN.</p>

</dd>
<dt id="T_REFOBJ"><a class="permalink" href="perlxstypemap.html#T_REFOBJ">#</a>T_REFOBJ</dt>
<dd>

<p>Like T_REFREF, except it does strict type checking (inheritance is not supported).</p>

<p>For <code>DESTROY</code> XSUBs only, a T_REFOBJ is optimized to a T_REFREF. This means the class check is skipped.</p>

</dd>
<dt id="T_OPAQUEPTR"><a class="permalink" href="perlxstypemap.html#T_OPAQUEPTR">#</a>T_OPAQUEPTR</dt>
<dd>

<p>This can be used to store bytes in the string component of the SV. Here the representation of the data is irrelevant to perl and the bytes themselves are just stored in the SV. It is assumed that the C variable is a pointer (the bytes are copied from that memory location). If the pointer is pointing to something that is represented by 8 bytes then those 8 bytes are stored in the SV (and length() will report a value of 8). This entry is similar to T_OPAQUE.</p>

<p>In principle the unpack() command can be used to convert the bytes back to a number (if the underlying type is known to be a number).</p>

<p>This entry can be used to store a C structure (the number of bytes to be copied is calculated using the C <code>sizeof</code> function) and can be used as an alternative to T_PTRREF without having to worry about a memory leak (since Perl will clean up the SV).</p>

</dd>
<dt id="T_OPAQUE"><a class="permalink" href="perlxstypemap.html#T_OPAQUE">#</a>T_OPAQUE</dt>
<dd>

<p>This can be used to store data from non-pointer types in the string part of an SV. It is similar to T_OPAQUEPTR except that the typemap retrieves the pointer directly rather than assuming it is being supplied. For example, if an integer is imported into Perl using T_OPAQUE rather than T_IV the underlying bytes representing the integer will be stored in the SV but the actual integer value will not be available. i.e. The data is opaque to perl.</p>

<p>The data may be retrieved using the <code>unpack</code> function if the underlying type of the byte stream is known.</p>

<p>T_OPAQUE supports input and output of simple types. T_OPAQUEPTR can be used to pass these bytes back into C if a pointer is acceptable.</p>

</dd>
<dt id="Implicit-array"><a class="permalink" href="perlxstypemap.html#Implicit-array">#</a><a id="Implicit"></a>Implicit array</dt>
<dd>

<p>xsubpp supports a special syntax for returning packed C arrays to perl. If the XS return type is given as</p>

<pre><code class="plaintext">array(type, nelem)</code></pre>

<p>xsubpp will copy the contents of <code>nelem * sizeof(type)</code> bytes from RETVAL to an SV and push it onto the stack. This is only really useful if the number of items to be returned is known at compile time and you don&#39;t mind having a string of bytes in your SV. Use T_ARRAY to push a variable number of arguments onto the return stack (they won&#39;t be packed as a single string though).</p>

<p>This is similar to using T_OPAQUEPTR but can be used to process more than one element.</p>

</dd>
<dt id="T_PACKED"><a class="permalink" href="perlxstypemap.html#T_PACKED">#</a>T_PACKED</dt>
<dd>

<p>Calls user-supplied functions for conversion. For <code>OUTPUT</code> (XSUB to Perl), a function named <code>XS_pack_$ntype</code> is called with the output Perl scalar and the C variable to convert from. <code>$ntype</code> is the normalized C type that is to be mapped to Perl. Normalized means that all <code>*</code> are replaced by the string <code>Ptr</code>. The return value of the function is ignored.</p>

<p>Conversely for <code>INPUT</code> (Perl to XSUB) mapping, the function named <code>XS_unpack_$ntype</code> is called with the input Perl scalar as argument and the return value is cast to the mapped C type and assigned to the output C variable.</p>

<p>An example conversion function for a typemapped struct <code>foo_t *</code> might be:</p>

<pre><code>static void
XS_pack_foo_tPtr(SV *out, foo_t *in)
{
  dTHX; /* alas, signature does not include pTHX_ */
  HV* hash = newHV();
  hv_stores(hash, &quot;int_member&quot;, newSViv(in-&gt;int_member));
  hv_stores(hash, &quot;float_member&quot;, newSVnv(in-&gt;float_member));
  /* ... */

  /* mortalize as thy stack is not refcounted */
  sv_setsv(out, sv_2mortal(newRV_noinc((SV*)hash)));
}</code></pre>

<p>The conversion from Perl to C is left as an exercise to the reader, but the prototype would be:</p>

<pre><code>static foo_t *
XS_unpack_foo_tPtr(SV *in);</code></pre>

<p>Instead of an actual C function that has to fetch the thread context using <code>dTHX</code>, you can define macros of the same name and avoid the overhead. Also, keep in mind to possibly free the memory allocated by <code>XS_unpack_foo_tPtr</code>.</p>

</dd>
<dt id="T_PACKEDARRAY"><a class="permalink" href="perlxstypemap.html#T_PACKEDARRAY">#</a>T_PACKEDARRAY</dt>
<dd>

<p>T_PACKEDARRAY is similar to T_PACKED. In fact, the <code>INPUT</code> (Perl to XSUB) typemap is identical, but the <code>OUTPUT</code> typemap passes an additional argument to the <code>XS_pack_$ntype</code> function. This third parameter indicates the number of elements in the output so that the function can handle C arrays sanely. The variable needs to be declared by the user and must have the name <code>count_$ntype</code> where <code>$ntype</code> is the normalized C type name as explained above. The signature of the function would be for the example above and <code>foo_t **</code>:</p>

<pre><code>static void
XS_pack_foo_tPtrPtr(SV *out, foo_t *in, UV count_foo_tPtrPtr);</code></pre>

<p>The type of the third parameter is arbitrary as far as the typemap is concerned. It just has to be in line with the declared variable.</p>

<p>Of course, unless you know the number of elements in the <code>sometype **</code> C array, within your XSUB, the return value from <code>foo_t ** XS_unpack_foo_tPtrPtr(...)</code> will be hard to decipher. Since the details are all up to the XS author (the typemap user), there are several solutions, none of which particularly elegant. The most commonly seen solution has been to allocate memory for N+1 pointers and assign <code>NULL</code> to the (N+1)th to facilitate iteration.</p>

<p>Alternatively, using a customized typemap for your purposes in the first place is probably preferable.</p>

</dd>
<dt id="T_DATAUNIT"><a class="permalink" href="perlxstypemap.html#T_DATAUNIT">#</a>T_DATAUNIT</dt>
<dd>

<p>NOT YET</p>

</dd>
<dt id="T_CALLBACK"><a class="permalink" href="perlxstypemap.html#T_CALLBACK">#</a>T_CALLBACK</dt>
<dd>

<p>NOT YET</p>

</dd>
<dt id="T_ARRAY"><a class="permalink" href="perlxstypemap.html#T_ARRAY">#</a>T_ARRAY</dt>
<dd>

<p>This is used to convert the perl argument list to a C array and for pushing the contents of a C array onto the perl argument stack.</p>

<p>The usual calling signature is</p>

<pre><code>@out = array_func( @in );</code></pre>

<p>Any number of arguments can occur in the list before the array but the input and output arrays must be the last elements in the list.</p>

<p>When used to pass a perl list to C the XS writer must provide a function (named after the array type but with &#39;Ptr&#39; substituted for &#39;*&#39;) to allocate the memory required to hold the list. A pointer should be returned. It is up to the XS writer to free the memory on exit from the function. The variable <code>ix_$var</code> is set to the number of elements in the new array.</p>

<p>When returning a C array to Perl the XS writer must provide an integer variable called <code>size_$var</code> containing the number of elements in the array. This is used to determine how many elements should be pushed onto the return argument stack. This is not required on input since Perl knows how many arguments are on the stack when the routine is called. Ordinarily this variable would be called <code>size_RETVAL</code>.</p>

<p>Additionally, the type of each element is determined from the type of the array. If the array uses type <code>intArray *</code> xsubpp will automatically work out that it contains variables of type <code>int</code> and use that typemap entry to perform the copy of each element. All pointer &#39;*&#39; and &#39;Array&#39; tags are removed from the name to determine the subtype.</p>

</dd>
<dt id="T_STDIO"><a class="permalink" href="perlxstypemap.html#T_STDIO">#</a>T_STDIO</dt>
<dd>

<p>This is used for passing perl filehandles to and from C using <code>FILE *</code> structures.</p>

</dd>
<dt id="T_INOUT"><a class="permalink" href="perlxstypemap.html#T_INOUT">#</a>T_INOUT</dt>
<dd>

<p>This is used for passing perl filehandles to and from C using <code>PerlIO *</code> structures. The file handle can used for reading and writing. This corresponds to the <code>+&lt;</code> mode, see also T_IN and T_OUT.</p>

<p>See <a href="perliol.html">perliol</a> for more information on the Perl IO abstraction layer. Perl must have been built with <code>-Duseperlio</code>.</p>

<p>There is no check to assert that the filehandle passed from Perl to C was created with the right <code>open()</code> mode.</p>

<p>Hint: The <a href="perlxstut.html">perlxstut</a> tutorial covers the T_INOUT, T_IN, and T_OUT XS types nicely.</p>

</dd>
<dt id="T_IN"><a class="permalink" href="perlxstypemap.html#T_IN">#</a>T_IN</dt>
<dd>

<p>Same as T_INOUT, but the filehandle that is returned from C to Perl can only be used for reading (mode <code>&lt;</code>).</p>

</dd>
<dt id="T_OUT"><a class="permalink" href="perlxstypemap.html#T_OUT">#</a>T_OUT</dt>
<dd>

<p>Same as T_INOUT, but the filehandle that is returned from C to Perl is set to use the open mode <code>+&gt;</code>.</p>

</dd>
</dl>


      </div>
      <div id="footer">
        <p>Perldoc Browser is maintained by Dan Book (<a href="https://metacpan.org/author/DBOOK">DBOOK</a>). Please contact him via the <a href="https://github.com/Grinnz/perldoc-browser/issues">GitHub issue tracker</a> or <a href="mailto:dbook@cpan.org">email</a> regarding any issues with the site itself, search, or rendering of documentation.</p>

<p>The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via the <a href="https://github.com/Perl/perl5/issues">Perl issue tracker</a>, the <a href="https://lists.perl.org/list/perl5-porters.html">mailing list</a>, or <a href="https://kiwiirc.com/client/irc.perl.org/p5p">IRC</a> to report any issues with the contents or format of the documentation.</p>


      </div>
    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js" integrity="sha512-/DXTXr6nQodMUiq+IUJYCt2PPOUjrHJ9wFrqpJ3XkgPNOZVfMok7cRw6CSxyCQxXn6ozlESsSh1/sMCTF1rL/g==" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js" integrity="sha512-ubuT8Z88WxezgSqf3RLuNi5lmjstiJcyezx34yIU2gAHonIi27Na7atqzUZCOoY4CExaoFumzOsFQ2Ch+I/HCw==" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
    <script src="../highlight.pack.js"></script>
    <script>hljs.highlightAll();</script>
  </body>
</html>
